import { ref } from 'vue'
import pagesContentAdd from '@/components/pages-content-add/pages-content-add.vue'

type CallbackFn = (item?: any) => void

export function useContentModel(newCal?: CallbackFn, ediCal?: CallbackFn) {
  const pagesModelRef = ref<InstanceType<typeof pagesContentAdd>>()
  const defaultConfig = ref({})
  const handAddClick = () => {
    if (pagesModelRef.value) {
      defaultConfig.value = {}
      pagesModelRef.value.centerDialogVisible = true
      newCal && newCal()
    }
  }
  const handEditClick = (item: any) => {
    if (pagesModelRef.value) {
      pagesModelRef.value.centerDialogVisible = true
      defaultConfig.value = { ...item }
      ediCal && ediCal(item)
    }
  }
  return [pagesModelRef, defaultConfig, handAddClick, handEditClick]
}
